package com.rico.kok.service;

import com.rico.kok.entity.Post;
import com.rico.kok.mapper.LikeMapper;
import com.rico.kok.mapper.PostMapper;
import com.rico.kok.service.interf.LikeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class LikeServiceIml implements LikeService {

    @Autowired
    private LikeMapper likeMapper;

    @Autowired
    private PostMapper postMapper;

    //更新内容点赞数量
    @Override
    @Transactional
    public int likePost(Post post) {
        likeMapper.like(post);
        post.setPostLike(1);
        return postMapper.updatePostLike(post);
    }

    @Override
    @Transactional
    public int disLike(Post post) {
        likeMapper.dislike(post);
        post.setPostLike(0);
        return postMapper.updatePostLike(post);
    }

    @Override
    public Integer isLike(Post post) {
        return likeMapper.isLike(post);
    }
}
